package org.coding.springbootdemocommandline.fileopr.controller;

import org.coding.springbootdemocommandline.fileopr.service.impl.ExcelOperationServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;

/**
 * ^ enjoy coding and be bugfree boy
 *
 * @author guoxh
 * @date 2020/11/7 3:35 下午
 * @desc
 **/
@RestController
@RequestMapping("/excel")
public class ExcelController {
    @Autowired
    private ExcelOperationServiceImpl excelOperationService;

    @GetMapping("/export")
    public void excelExport(HttpServletResponse response) throws IOException {
        OutputStream os = null;
        response.setContentType("application/octet-stream;charset=ISO8859-1");
        response.addHeader("Content-Disposition", "attachment;filename=" + "fileName" + ".xlsx");
        response.addHeader("Pargam", "no-cache");
        response.addHeader("Cache-Control", "no-cache");
        os = response.getOutputStream();

        excelOperationService.exportExcel();
    }
}
